package com.ruoyi.web.controller.system.city;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import com.ruoyi.common.utils.poi.ExcelUtil;
import com.ruoyi.system.domain.city.CityInfo;
import com.ruoyi.system.service.city.ICityInfoService;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.ruoyi.common.annotation.Log;
import com.ruoyi.common.core.controller.BaseController;
import com.ruoyi.common.core.domain.AjaxResult;
import com.ruoyi.common.enums.BusinessType;
import com.ruoyi.common.core.page.TableDataInfo;

/**
 * 资讯Controller
 * 
 * @author cjq
 * @date 2023-10-15
 */
@RestController
@RequestMapping("/system/info")
public class CityInfoController extends BaseController
{
    @Autowired
    private ICityInfoService cityInfoService;

    /**
     * 查询资讯列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:list')")
    @GetMapping("/list")
    public TableDataInfo list(CityInfo cityInfo)
    {
        startPage();
        List<CityInfo> list = cityInfoService.selectCityInfoList(cityInfo);
        return getDataTable(list);
    }

    /**
     * 导出资讯列表
     */
    @PreAuthorize("@ss.hasPermi('system:info:export')")
    @Log(title = "资讯", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, CityInfo cityInfo)
    {
        List<CityInfo> list = cityInfoService.selectCityInfoList(cityInfo);
        ExcelUtil<CityInfo> util = new ExcelUtil<CityInfo>(CityInfo.class);
        util.exportExcel(response, list, "资讯数据");
    }

    /**
     * 获取资讯详细信息
     */
    @PreAuthorize("@ss.hasPermi('system:info:query')")
    @GetMapping(value = "/{infoId}")
    public AjaxResult getInfo(@PathVariable("infoId") Long infoId)
    {
        return success(cityInfoService.selectCityInfoByInfoId(infoId));
    }

    /**
     * 新增资讯
     */
    @PreAuthorize("@ss.hasPermi('system:info:add')")
    @Log(title = "资讯", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody CityInfo cityInfo)
    {
        return toAjax(cityInfoService.insertCityInfo(cityInfo));
    }

    /**
     * 修改资讯
     */
    @PreAuthorize("@ss.hasPermi('system:info:edit')")
    @Log(title = "资讯", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody CityInfo cityInfo)
    {
        return toAjax(cityInfoService.updateCityInfo(cityInfo));
    }

    /**
     * 删除资讯
     */
    @PreAuthorize("@ss.hasPermi('system:info:remove')")
    @Log(title = "资讯", businessType = BusinessType.DELETE)
	@DeleteMapping("/{infoIds}")
    public AjaxResult remove(@PathVariable Long[] infoIds)
    {
        return toAjax(cityInfoService.deleteCityInfoByInfoIds(infoIds));
    }
}
